package Main;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import javax.swing.Timer;

import Game.Dealer;
import Game.MouseHandler;

public class GamePanel extends JPanel{
	
	private Dealer dealer;
	private Timer timer;
	private Image backImage;
	
	ActionListener update = new ActionListener() {
		
		@Override
		public void actionPerformed(ActionEvent e) {
			dealer.update();
			repaint();
			
		}
	}; 
	
	public GamePanel() {
        setFocusable(true);
        setDoubleBuffered(true);
        initBG();
        dealer = new Dealer();
        addMouseListener(new MouseHandler(dealer));
        timer = new Timer(10, update);
        timer.start();
    }
	
	private void initBG(){
		try {
			backImage = ImageIO.read(new File("images\\back.jpg"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(backImage, 0, 0, null);
        dealer.draw(g);
        g.dispose();
    }
}
